Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hardcoded path to i18n file if not provided #290

Merged
merged 3 commits into from
Feb 26, 2025

Conversation

carlos-granados
Copy link
Contributor

Alternate solution to the problem described in Behat/Behat#1602 and Behat/Behat#1603. Since the file that CachedArrayKeywords needs to load is in the same package, it does not need to be told its location by another package. We keep the option of passing a file name in case someone is using this class to load an i18n file from some other location. After this is merged in this package we should update Behat so that it does not attempt to provide the path to the file

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good solution, but maybe we should also revert moving the files in the src directory, at least for now?

Otherwise it will only work if we release Gherkin and Behat at the same time (and bump the minimum version requirement in Behat).

Also Behat may not be the only thing using this class with a path to the Gherkin i18n file - I'm not sure the limited benefit we get from flattening the directory structure is worth even a small risk of causing problems for other people?

@carlos-granados
Copy link
Contributor Author

I think this is a good solution, but maybe we should also revert moving the files in the src directory, at least for now?

Otherwise it will only work if we release Gherkin and Behat at the same time (and bump the minimum version requirement in Behat).

Also Behat may not be the only thing using this class with a path to the Gherkin i18n file - I'm not sure the limited benefit we get from flattening the directory structure is worth even a small risk of causing problems for other people?

@acoulton I think that moving the files is a good move that we should keep. No one should have been depending on the location of files, and if they did they would need to work to fix that unnecessary dependency. But it is true that currently this makes the update cumbersome, having to release Gherkin and Behat at the same time. What I think we could do:

  • Create here a new v4.12.0 release branch not from the current master but from a previous point in the code before the files were moved.
  • Move this PR to point to this new branch (adjusting the file location to the old location)
  • Once this PR is merged, release the v4.12.0 version. This would provide a version that anyone could use to break the link with the location of the file. It would work both with code which provided the file location and for code that did not
  • Merge this release branch into master, adjusting the file location to the new location
  • Update Behat to require version v4.12.0 and adjust the code to stop sending the file location parameter. We would then have a Behat version that we could release whenever convenient

What do you think?

@acoulton
Copy link
Contributor

No one should have been depending on the location of files, and if they did they would need to work to fix that unnecessary dependency.

Normally I would agree (and did when I merged #288).

However, discovering now that we ship a class that it seems would always/usually need to be used with a path in this repo it seems a little more reasonable that people might have being doing that...

But I think your solution is good, I think the majority of users will be using this with Behat so as long as that upgrade path is smooth that's probably ok.

@carlos-granados carlos-granados changed the base branch from master to release-4.12.0 February 26, 2025 08:17
@carlos-granados
Copy link
Contributor Author

@acoulton I created the new release branch, modified this PR to point to the new branch and modified the code to point to the old location

@acoulton
Copy link
Contributor

@carlos-granados thanks - I noticed there's a test that was also specifying the path (both in the setup and the assertions). I've pushed a commit to your branch that removes the constructor argument, so that should test should now prove that the default file location is correct (it will fail when the files are moved).

While doing that, I wondered if it would be clearer to use a named constructor rather than an optional argument - something like:

public static function withGherkinI18n(): self {
    // or maybe withDefaultKeywords // withDefaultTranslations?
    return new self(__DIR__ . '/../../../../i18n.php');
}

// and then leave the constructor parameter required.

That way it's explicit to end users what this class does with a null / missing constructor argument - CachedArrayKeywords alone isn't that obvious what it's actually loading / caching...

What do you think?

@carlos-granados
Copy link
Contributor Author

@carlos-granados thanks - I noticed there's a test that was also specifying the path (both in the setup and the assertions). I've pushed a commit to your branch that removes the constructor argument, so that should test should now prove that the default file location is correct (it will fail when the files are moved).

While doing that, I wondered if it would be clearer to use a named constructor rather than an optional argument - something like:

public static function withGherkinI18n(): self {
    // or maybe withDefaultKeywords // withDefaultTranslations?
    return new self(__DIR__ . '/../../../../i18n.php');
}

// and then leave the constructor parameter required.

That way it's explicit to end users what this class does with a null / missing constructor argument - CachedArrayKeywords alone isn't that obvious what it's actually loading / caching...

What do you think?

Good idea, I think that withDefaultKeywords would be the best option

@acoulton
Copy link
Contributor

Good idea, I think that withDefaultKeywords would be the best option

I can update that in this PR, unless you want to?

@carlos-granados
Copy link
Contributor Author

Good idea, I think that withDefaultKeywords would be the best option

I can update that in this PR, unless you want to?

Yes, please, go ahead I am busy with something else at the moment

Allows end-users to create an instance with the i18n file provided by
us, without an external dependency on the path to the file.

Co-authored-by: Carlos Granados <[email protected]>
@acoulton
Copy link
Contributor

@carlos-granados done - let me know if this looks OK to you and I can squash-merge and do the release notes.

Copy link
Contributor Author

@carlos-granados carlos-granados left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @acoulton

@acoulton acoulton merged commit c5d8733 into Behat:release-4.12.0 Feb 26, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants